<?php defined("MAIN_DIR") or die("No direct access");

require_once ADMIN.HEADFILE;
?>
<script type="text/javascript">
page = "home";
func = add_home;
</script>
<div align="left">
<h1>Список кредитов (Ипотека)</h1><?php
$home_query = "
select `H`.`home_id`,`H`.`regionally`,`H`.`name`,`C`.`path`,`C`.`city_name`,`B`.`name` as `b_name`
from `bank` as `B`
left join `city` as `C`
	on `B`.`city_id` = `C`.`city_id`
,`home` as `H`
where
	`H`.`bank_id` = `B`.`bank_id`
order by `home_id`";

$limit = 10;
$home_res = mysql_query($home_query);
$count = mysql_num_rows($home_res);
$page = 1;
if (isset($_GET['page']))
	$page = $_GET['page'];
$max_page = ceil($count/$limit);
if ($max_page == 0)
	$max_page++;
if ($page > $max_page)
	$page = $max_page;
elseif ($page < 1)
	$page = 1;
$start_list = (ceil($page)-1)*$limit;
$home_query .= " limit $start_list,$limit";
$home_res = mysql_query($home_query);
$home_count = mysql_num_rows($home_res);
?>
<input type='text' id='search' />
<table cellpadding="5" cellspacing="0" class='light'>
	<tr id='header'>
		<td width="30px" style="border-bottom:1px gray solid">ID</td>
		<td width="300px" style="border-bottom:1px gray solid">Название</td>
		<td width="300px" style="border-bottom:1px gray solid">Банк</td>
		<td width="200px" style="border-bottom:1px gray solid">Действия</td>
	</tr><?php
	while ($home_row = mysql_fetch_array($home_res))
	{
		?><tr>
			<td><?php echo $home_row['home_id']?></td>
			<td><a href='<?php echo "/$home_row[path]/credits/home/".$home_row['home_id']?>'><?php echo $home_row['name']?></td>
			<td>
				<?php echo $home_row['b_name']." (".($home_row['regionally'] ? "Межрегионально" : $home_row['city_name']).")"; ?>
			</td>
			<td>
				<a href='/admin/credits/home/edit/<?php echo $home_row['home_id']?>'>Редактировать</a> |
				<a onclick='return confirm_del()' href='/admin/credits/home/delete/<?php echo $home_row['home_id']?>'>Удалить</a>
			</td>
		</tr><?php
	}
?></table>
<br /><a href='/admin/credits/home/add/'>Добавить</a>
<br /><?php require_once APP."pageskin.php"; ?>
</div>

<?php require_once ADMIN.FOOTERFILE; ?>